Security News
Research
Supply Chain Attack on Rspack npm Packages Injects Cryptojacking Malware
A supply chain attack on Rspack's npm packages injected cryptomining malware, potentially impacting thousands of developers.
io-ts-types
Advanced tools
The io-ts-types package provides additional types and combinators for use with io-ts, a runtime type system for IO decoding/encoding in TypeScript. It extends the functionality of io-ts by offering more complex and useful types that are commonly needed in real-world applications.
DateFromISOString
This feature allows you to decode ISO string dates into JavaScript Date objects. It is useful for handling date strings in JSON APIs.
const { DateFromISOString } = require('io-ts-types');
const t = require('io-ts');
const DateType = DateFromISOString;
const result = DateType.decode('2023-10-01T00:00:00Z');
console.log(result); // Right(new Date('2023-10-01T00:00:00Z'))
NonEmptyString
This feature ensures that a string is not empty. It is useful for validating user input where empty strings are not allowed.
const { NonEmptyString } = require('io-ts-types');
const t = require('io-ts');
const NonEmptyStringType = NonEmptyString;
const result = NonEmptyStringType.decode('Hello');
console.log(result); // Right('Hello')
UUID
This feature validates that a string is a valid UUID. It is useful for ensuring that identifiers conform to the UUID format.
const { UUID } = require('io-ts-types');
const t = require('io-ts');
const UUIDType = UUID;
const result = UUIDType.decode('123e4567-e89b-12d3-a456-426614174000');
console.log(result); // Right('123e4567-e89b-12d3-a456-426614174000')
Option
This feature allows you to handle optional values in a functional way using the Option type from fp-ts. It is useful for dealing with nullable fields in a type-safe manner.
const { optionFromNullable } = require('io-ts-types');
const t = require('io-ts');
const OptionType = optionFromNullable(t.string);
const result = OptionType.decode(null);
console.log(result); // Right(none)
const result2 = OptionType.decode('Hello');
console.log(result2); // Right(some('Hello'))
Zod is a TypeScript-first schema declaration and validation library. It provides a similar functionality to io-ts-types but with a different API and philosophy. Zod is more focused on developer experience and ease of use, while io-ts-types is more focused on functional programming paradigms.
Yup is a JavaScript schema builder for value parsing and validation. It is similar to io-ts-types in that it provides a way to define and validate complex data structures. However, Yup is more widely used in the React ecosystem and has a more imperative API compared to the functional approach of io-ts-types.
Superstruct is a library for validating and transforming data structures in JavaScript and TypeScript. It offers similar functionality to io-ts-types but with a simpler and more intuitive API. Superstruct is designed to be lightweight and easy to use, making it a good alternative for those who prefer a less functional approach.
A collection of runtime types and combinators for use with io-ts
To install the stable version:
npm i io-ts-types
Note. io-ts-types
depends on
starting from 0.5.0
you must install fp-ts
, io-ts
, newtype-ts
and monocle-ts
manually (fp-ts
, io-ts
, newtype-ts
and monocle-ts
are listed in peerDependency
)
io-ts-types version | required typescript version |
---|---|
0.5.x | 3.5+ |
0.4.x | 3.1+ |
FAQs
A collection of codecs and combinators for use with io-ts
The npm package io-ts-types receives a total of 256,362 weekly downloads. As such, io-ts-types popularity was classified as popular.
We found that io-ts-types demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Research
A supply chain attack on Rspack's npm packages injected cryptomining malware, potentially impacting thousands of developers.
Research
Security News
Socket researchers discovered a malware campaign on npm delivering the Skuld infostealer via typosquatted packages, exposing sensitive data.
Security News
Sonar’s acquisition of Tidelift highlights a growing industry shift toward sustainable open source funding, addressing maintainer burnout and critical software dependencies.